//
// Created by Tony on 2024/7/30.
//

#include "NativeMethodTable.h"
#include <string>

namespace RtCode {

void NativeMethodTable::add(const string& className, const string& methodName,
                            NativeMethod method) {
    auto key = buildKey(className, methodName);
    mMethodTable.emplace(key, method);
}

NativeMethod NativeMethodTable::get(const string& className, const string& methodName) {
    auto key = buildKey(className, methodName);
    auto method = mMethodTable.find(key);
    if (method != mMethodTable.end()) {
        return method->second;
    }
    return nullptr;
}

std::string NativeMethodTable::buildKey(const string& className, const string& methodName) {
    return string{className}.append("$").append(methodName);
}

} // namespace RtCode
